 <?php 
//error_reporting(0); 
        // $appid = 'wx583c13204681c129';
        // $secret = '5ac902f23a237813e6871303357b33a8';
        //声明CODE，获取小程序传过来的CODE
        $code = $_GET['code'];
        if($_GET['code']){

        //配置appid
        $appid = 'wx583c13204681c129';
        //配置appscret
        $secret = '5ac902f23a237813e6871303357b33a8';
        //api接口

        $url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' . $appid . '&secret=' . $secret . '&js_code=' . $code . '&grant_type=authorization_code';

        $weixin=file_get_contents($url);

        $session_key = $res->session_key;
        $openid = $res->openid;

        $jsondecode=json_decode($weixin);

        $array=get_object_vars($jsondecode);

        echo json_encode($array);
        
  
}else{
	echo "获取失败了";
}


        // $res = json_decode(file_get_contents($url));

        // $arr = get_object_vars($res);

        // $openid = $arr['openid'];
        // $session_key = $arr['session_key'];

        // echo $arr;
        // echo $openid;

      
        ?>
